package com.dkd.http.controller;

import com.dkd.entity.PolicyEntity;
import com.dkd.entity.VmPolicyEntity;
import com.dkd.entity.VmTypeEntity;
import com.dkd.entity.dto.ApplyPolicyDto;
import com.dkd.entity.dto.PolicyPageQuery;
import com.dkd.entity.vo.PolicyPageVo;
import com.dkd.entity.vo.VmPolicyDeatilVo;
import com.dkd.entity.vo.VmTypeVo;
import com.dkd.service.PolicyService;
import com.dkd.service.VmPolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 策略管理
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "策略相关接口")
@RequestMapping("/policy")
public class PolicyController {
    private final PolicyService policyService;
    private final VmPolicyService vmPolicyService;
    @GetMapping
    @ApiOperation("策略列表")
    public PolicyPageVo pagePolicy(PolicyPageQuery policyPageQuery){
        return policyService.getPolicy(policyPageQuery);
    }

    @GetMapping("/{policyId}")
    @ApiOperation("策略详情")
    public List<VmPolicyDeatilVo> getPolicy(@PathVariable("policyId")Integer policyId){
        return policyService.getPolicyById(policyId);
    }
    @PutMapping("/{policyId}")
    public boolean updatePolicy(@RequestBody PolicyEntity policyEntity){
        return policyService.updateById(policyEntity);
    }
    @PostMapping
    public boolean addPolicy(@RequestBody PolicyEntity policyEntity){
        return policyService.save(policyEntity);
    }

    @DeleteMapping("/{policyId}")
    public boolean deletePolicy(@PathVariable("policyId")Integer policyId){
        vmPolicyService.lambdaUpdate().eq(VmPolicyEntity::getPolicyId,policyId).remove();
        return policyService.removeById(policyId);
    }
    @GetMapping("/vmPolicy/{innerCode}")
    public VmPolicyEntity getVmPolicy(@PathVariable("innerCode") String innerCode){
        return vmPolicyService.lambdaQuery().eq(VmPolicyEntity::getInnerCode,innerCode).one();
    }


}
